package project23;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        HashMap<String, Integer> maps = new HashMap<>();
        String key;
        ArrayList<String> arr = new ArrayList<>();
        while(!(key=sc.next()).equals("end"))
        {
            if(!arr.contains(key))
            {
                arr.add(key);
            }
            if(maps.containsKey(key))
            {
                maps.put(key,maps.get(key)+1);
            }
            else
                maps.put(key,1);
        }
        for(int i=0;i<arr.size()-1;++i)
        {
            for(int k=0;k<arr.size()-i-k;++k)
            {
                String n;
                if(maps.get(arr.get(k))<maps.get(arr.get(k+1)))
                {
                    n=arr.get(k);
                    arr.set(k,arr.get(k+1));
                    arr.set(k+1,n);
                }
            }
        }
        for (int i=0;i<arr.size();++i)
        {
            System.out.println(arr.get(i)+" "+maps.get(arr.get(i)));
        }
    }
}
